package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resource")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    @PostMapping("/list")
    public ResponseResult<List<ResourceVo>> list(@RequestBody ResourceDto resourceDto) {
        List<ResourceVo> resourceVoList = resourceService.list(resourceDto);
        return ResponseResult.success(resourceVoList);
    }

    @PostMapping("/tree")
    public ResponseResult<TreeVo> resourceTree(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.resourceTree(resourceDto);
        return ResponseResult.success(treeVo);
    }

    @PutMapping
    public ResponseResult createResource(@RequestBody ResourceDto resourceDto) {
        resourceService.createResource(resourceDto);
        return ResponseResult.success();
    }
}
